<?php
$context=stream_context_create(['http'=>[
    'method'=>'POST',//必须要有，默认是GET方法
    'header'=>'Content-type:application/x-www-form-urlencoded',
    'Content'=>http_build_query([
        'xh'=>'金艳丽',
        'pwd'=>'1q@',
        'rememberMe'=>'on',
    ]),
//    'follow_location'=>0,
    'max_redirects'=>1,
]]);
//$html=file_get_contents('http://localhost:8080/login.php',context: $context);
//echo $html;
//print_r($http_response_header);
$headers=get_headers('http://localhost:8080/login.php',true,$context);
print_r($headers);
$sessionId=null;
foreach ($headers['Set-Cookie'] as $header){
    if (str_starts_with($headers,'PHPSESSID=')){
        $sessionId=$headers;
    }
}
$context=stream_context_create(['http'=>[
    'header'=>"Cookie: $sessionId",
]]);
$html=file_get_contents( 'http://localhost:8080/index.php',context: $context);
//echo $html;
preg_match_all('@<tr><td>(\d+)</td><td>([^<]+)</td><td>([^<]+)</td>@',$html,$m,PREG_SET_ORDER);
//print_r($m[0]);
foreach ($m as $user){
    echo "$user[1]\t$user[2]\t$user[3]\n";

    //利用登录的管理员账号来删除所有用户
    file_get_contents('http://localhost:8080/delete.php?xh=213110601',$user[1],context: $context);
}
